-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')

local MouseIconSystem = Class:derive('InputMouseIconSystem')

function MouseIconSystem:new(domain)
    self.name = 'InputMouseIconSystem'
    self.domain = domain
end

function MouseIconSystem:setCursor(domain, cursor)
    local world = domain.world
    local ImagesManager = world:getManager('ImagesManager')
    local sprite = ImagesManager:getImageTexture(cursor)
    local cur = love.mouse.newCursor(sprite.imagedata, 0, 0)
    love.mouse.setCursor(cur)
end

function MouseIconSystem:update(dt)
    local domain = self.domain
    local icons = domain.components['Icon']
    if icons then
        for _, c in pairs(icons) do
            MouseIconSystem:setCursor(domain, c.icon)
            c.entity:deleteComponent(c)
        end
    end
end

return MouseIconSystem
